<?php
namespace app\api\controller;

use app\common\model\User as UserModel;
use app\common\validate\User as UserValidate;

class User extends Base
{
	public function index()
	{
		return cdm(200,$this->user,'');
	}

	public function create()
	{
		
	}

	public function save()
	{
		
	}

	public function read($id)
	{

	}

	public function edit($id)
	{

	}

	public function update($id)
	{
		if(empty($this->user)){
			return cdm(401,0,'请先登录!');
		}
		$data['password'] = request_input('password','');
		$data['password_confirm'] = request_input('password_confirm','');
		$data['name'] = request_input('name','');
		$data['avatar'] = request_input('avatar','');
		$data['phone'] = request_input('phone',0);
		$data['email'] = request_input('email','');
		$data['gender'] = request_input('gender',0);
		$data['province'] = request_input('province',0);
		$data['city'] = request_input('city',0);
		$data['county'] = request_input('county',0);
		$data['desc'] = request_input('desc','');

		if(empty($data['password']) && empty($data['password_confirm'])){
			$data['password'] = $this->user->password;
			$data['password_confirm'] = $this->user->password;
		}

		$validate = new UserValidate;
		if (!$validate->check($data)) {
			return json(msg(500, 0, $validate->getError()));
		}

		$this->user->save($data);
		return cdm(200, 1, '修改成功!');
	}

	public function delete($id)
	{

	}
}